/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.util.HashMap;

/**
 *
 * @author Cyril
 */
public class Noeud {
    private int id;
    private String name;
    private String xpath;
    private int docId;
    private int longueur;
    private HashMap<Terme,Integer> nbOccursParTerme;
    
    public Noeud(int id, String name, String xpath, int docId) {
        this.id = id;
        this.longueur = 0;
        this.name = name;
        this.xpath = xpath;
        this.docId = docId;
        this.nbOccursParTerme = new HashMap<Terme,Integer>();
    }

    
    public void addOccur(Terme t) {
        this.longueur++;
        Integer i;
        if ((i = nbOccursParTerme.get(t))==null) {
            this.nbOccursParTerme.put(t, 1);
        } else {
            this.nbOccursParTerme.put(t,i+1);
        }
    }
    
    public int getNbTermTotal() {
        return this.longueur;
    }
    
    public int getNbTermDiff() {
        return this.nbOccursParTerme.size();
    }
    
    public int getNbOccursDe(Terme t) {
        return this.nbOccursParTerme.get(t);
    }

    public int getId() {
        return this.id;
    }
    
    public int getDocId() {
        return this.docId;
    }
    
    public String getValue() {
        //id_noeud, longueur, poids, nom
        StringBuilder res = new StringBuilder();
        res.append("('");
        res.append(this.id).append("','").append(this.longueur).append("','").append(1).append("','").append(this.name);
        res.append("','").append(this.docId).append("','").append(this.xpath);
        res.append("')");
        return res.toString();
    }
}
